package com.ruoyi.shop.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shop.domain.TransLog;
import com.ruoyi.shop.service.ITransLogService;
import com.ruoyi.web.service.IMemberService;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/transLog")
@RequiredArgsConstructor
public class TransLogController extends BaseController
{
    private String prefix = "log";

    private final ITransLogService transLogService;

    @RequiresPermissions("order:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    @RequiresPermissions("order:log:view")
    @GetMapping(value = "/dealListView")
    public String dealListView()
    {
        return prefix + "/dealTrans";
    }

    /**
     * 查询未完成订单列表
     */
    @RequiresPermissions("order:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransLog transLog)
    {
        startPage();
        List<TransLog> list = transLogService.selectTransLogList(transLog);
        return getDataTable(list);
    }

    /**
     * 查询已完成订单列表
     */
    @RequiresPermissions("order:log:list")
    @PostMapping("/dealList")
    @ResponseBody
    public TableDataInfo dealList(TransLog transLog)
    {
        startPage();
        List<TransLog> list = transLogService.selectDealList(transLog);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("order:log:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransLog transLog)
    {
        List<TransLog> list = transLogService.selectTransLogList(transLog);
        ExcelUtil<TransLog> util = new ExcelUtil<TransLog>(TransLog.class);
        return util.exportExcel(list, "订单数据");
    }

    /**
     * 新增订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单
     */
    @RequiresPermissions("order:log:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransLog transLog)
    {
        return toAjax(transLogService.insertTransLog(transLog));
    }

    /**
     * 修改订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TransLog transLog = transLogService.selectTransLogById(id);
        mmap.put("transLog", transLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单
     */
    @RequiresPermissions("order:log:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransLog transLog)
    {
        return toAjax(transLogService.updateTransLog(transLog));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("order:log:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transLogService.deleteTransLogByIds(ids));
    }
}
